package com.smit.dvb.service;

import com.smit.dvb.DVBServiceInfo;
import com.smit.dvb.jni.DVB;
import com.smit.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * DVB节目
 */
public class ServiceControl {
    
    /** 有TS流 */
    public static final int MSG_SERVICE_HAS_TS = 401;
    /** 清流且复位player*/
    public static final int MSG_SERVICE_FREE_AND_RESET_PLAYER = 402;
    /** 清流且不复位player */
    public static final int MSG_SERVICE_FREE_WITHOUT_RESET_PLAYER = 403;
    /** 加密节目 */
    public static final int MSG_SERVICE_SCRAMBLED = 404;
    /** 准备player */
    public static final int MSG_SERVICE_TS_PLAYER_PREPARED = 405;
    /** 无信号或信号弱 */
    public static final int MSG_SERVICE_SIGNAL_BAD = 406;
    /** 信号好 */
    public static final int MSG_SERVICE_SIGNAL_GOOD = 407;
    /** 停止player */
    public static final int MSG_SERVICE_STOPPED = 408;
    
    private static final String TAG = "ServiceControl";
    private final List<IServiceCallback> serviceCallbackList = new ArrayList<IServiceCallback>();

    /**
     * <p> 添加一个service回调 <br/>
     *
     * @param callback 回调接口
     */
    public void addCallback(IServiceCallback callback) {
        if (!serviceCallbackList.contains(callback)) {
            serviceCallbackList.add(callback);
        }
    }

    /**
     * <p> 移除一个service回调 <br/>
     *
     * @param callback 回调接口<br/>
     */
    public void removeCallback(IServiceCallback callback) {
        if (serviceCallbackList.contains(callback)) {
            serviceCallbackList.remove(callback);
        }
    }

    /**
     * <p> 获取所有sevice回调对象 <br/>
     *
     * @return 返回所有注册进来的回调
     */
    public List<IServiceCallback> getCallbackList() {
        return serviceCallbackList;
    }

    /**
     * 播放指定的Service
     * @param index Service的索引,0开始
     * @return int 0成功，其他失败
     */
    public int playServiceByIndex(int index) {
        LogUtil.info(TAG, "playServiceByIndex start>>>");
        return DVB.getInstance().playServiceByIndex(index);
    }

    /**
     * Service是否加扰
     * @param index Service的索引
     * @return true加扰，false非加扰
     */
    public boolean isServiceDescramble(int index) {
        return false;
    }

    /**
     * 获取所有的Service信息
     * @return 所有节目信息
     */
    public DVBServiceInfo[] getAllServices() {
        return DVB.getInstance().getAllServices();
    }

    /**
     * 停止DVB Service复位
     */
    public void stopDVBService() {
        DVB.getInstance().stopDVBService();
    }

}